
library( ggplot2 )



# #### FIGURE 1
# #### PLOT TREATMENT EFFECTS ON MEAN CORRECT AND MEAN DK, COMPARING PLATFORMS (use weights for CCES and Google Surveys, no weights for MTurk)
# stata code looks like this:
#reg dunno encourageguess if cces==1
#reg dunno encourageguess if google==1
#reg dunno encourageguess if mturk==1
#reg correct encourageguess if cces==1
#reg correct encourageguess if google==1
#reg correct encourageguess if mturk==1
platforms <- data.frame(
	condition = factor(
			c( "Treatment effect\non DK responses", "Treatment effect\non DK responses", "Treatment effect\non DK responses", "Treatment effect\non correct responses", "Treatment effect\non correct responses", "Treatment effect\non correct responses" ),
			levels = c( "Treatment effect\non DK responses", "Treatment effect\non correct responses" ),
			ordered = TRUE
	),
	estimate = 	c(  -0.14, -0.12, -0.33, -0.06,  0.03, 0.30 ),
	lower = 	c(  -0.30, -0.30, -0.45, -0.27, -0.16, 0.14 ),
	upper = 	c(   0.03,  0.06, -0.20,  0.15,  0.22, 0.46 ),
	Platform = factor( 
		c( "CCES", "Google", "MTurk" ),
		levels=c( "CCES", "Google", "MTurk" ), 
		ordered=TRUE 
	)
)
#tiff( file="C:/Users/arb63/Dropbox/Work/Research/2015 state constitutions/constitutional veneration experiment/survey platform knowledge project/2019-07 streamlined for PS/BROWN-POPE_19-00132 figure 1.tiff", width=5, height=6, units="in", res=1200 ) ### UNCOMMENT THIS LINE AND THE ONE BELOW GGPLOT() TO SAVE AS A TIFF
ggplot(
	data = platforms,
	aes( x=condition, y=estimate, ymin=lower, ymax=upper, colour=Platform )
) +
	scale_colour_grey(start = 0.8, end = 0) +	## omit this to use color rather than grayscale
	theme_bw() +
	theme( aspect.ratio=5/3 ) +
	geom_point(position = position_dodge(width = 0.2)) +
	geom_errorbar(position = position_dodge(width = 0.2), width = 0.1)	 +
	scale_y_continuous( limits=c(-1.1,1.1), breaks=c(-1,0,1), name="Mean Effect of Encouraging Guessing Rather Than Encouraging DK", expand=c(0,0) ) +
	scale_x_discrete( name="" )
#dev.off() ### UNCOMMENT THIS ONE TOO TO SAVE AS A TIFF







# #### FIGURE A1
# #### PLOT MEAN DK AND 95% CI BY CONDITION AND PLATFORM
# Use the stata do file for cross-platform comparison to get the data plotted here. Looks like this:
#reg dunno if encourageguess==1 & cces==1
#reg dunno if encourageguess==1 & google==1
#reg dunno if encourageguess==1 & mturk==1
#reg dunno if encouragedunno==1 & cces==1
#reg dunno if encouragedunno==1 & google==1
#reg dunno if encouragedunno==1 & mturk==1
dunno <- data.frame(
	metric = factor( 
		c( "Encourage\nguessing", "Encourage\nguessing", "Encourage\nguessing", "Encourage marking\ndon't know", "Encourage marking\ndon't know", "Encourage marking\ndon't know" ),
		levels=c( "Encourage\nguessing", "Encourage marking\ndon't know" ), 
		ordered=TRUE ),
	estimate = 	c( 0.86, 0.91, 0.58, 0.99, 1.03, 0.91 ),
	lower = 	c( 0.75, 0.79, 0.51, 0.86, 0.90, 0.81 ),
	upper = 	c( 0.97, 1.04, 0.66, 1.12, 1.16, 1.01 ),
	Platform = factor( 
		c( "CCES", "Google", "MTurk" ),
		levels=c( "CCES", "Google", "MTurk" ), 
		ordered=TRUE )
)
ggplot( 
	data = dunno,
	aes( x=metric, y=estimate, ymin=lower, ymax=upper, colour=Platform )
	) +
	theme_bw() +
	theme( aspect.ratio=5/3 ) +
	geom_point(position = position_dodge(width = 0.2)) +
	geom_errorbar(position = position_dodge(width = 0.2), width = 0.1)	 +
	scale_y_continuous( limits=c(-0.1,4.1), breaks=c(0,1,2,3,4), name="Mean Number of DK Responses", expand=c(0,0) ) +
	scale_x_discrete( name="" )



# #### FIGURE A2
# #### PLOT MEAN CORRECT AND 95% CI BY CONDITION AND PLATFORM
# Use the stata do file for cross-platform comparison to get the data plotted here. Looks like this:
#reg correct if encourageguess==1 & cces==1
#reg correct if encourageguess==1 & google==1
#reg correct if encourageguess==1 & mturk==1
#reg correct if encouragedunno==1 & cces==1
#reg correct if encouragedunno==1 & google==1
#reg correct if encouragedunno==1 & mturk==1
correct <- data.frame(
	metric = factor( 
		c( "Encourage\nguessing", "Encourage\nguessing", "Encourage\nguessing", "Encourage marking\ndon't know", "Encourage marking\ndon't know", "Encourage marking\ndon't know" ),
		levels=c( "Encourage\nguessing", "Encourage marking\ndon't know" ), 
		ordered=TRUE ),
	estimate = 	c( 2.79, 2.85, 3.22, 2.85, 2.81, 2.91 ),
	lower = 	c( 2.64, 2.72, 3.11, 2.70, 2.68, 2.79 ),
	upper = 	c( 2.93, 2.98, 3.33, 3.00, 2.96, 3.04 ),
	Platform = factor( 
		c( "CCES", "Google", "MTurk" ),
		levels=c( "CCES", "Google", "MTurk" ), 
		ordered=TRUE )
)
ggplot( 
	data = correct,
	aes( x=metric, y=estimate, ymin=lower, ymax=upper, colour=Platform )
	) +
	theme_bw() +
	theme( aspect.ratio=5/3 ) +
	geom_point(position = position_dodge(width = 0.2)) +
	geom_errorbar(position = position_dodge(width = 0.2), width = 0.1)	 +
	scale_y_continuous( limits=c(-0.1,4.1), breaks=c(0,1,2,3,4), name="Mean Number of Correct Responses", expand=c(0,0) ) +
	scale_x_discrete( name="" )




# #### FIGURE A3 (same as figure 1, but with survey weights applied)
# #### PLOT TREATMENT EFFECTS ON MEAN CORRECT AND MEAN DK, COMPARING PLATFORMS (use weights for CCES and Google Surveys, no weights for MTurk)
# stata code looks like this:
#reg dunno encourageguess if cces==1 [pweight=weight]
#reg dunno encourageguess if google==1 [pweight=weight]
#reg dunno encourageguess if mturk==1
#reg correct encourageguess if cces==1 [pweight=weight]
#reg correct encourageguess if google==1 [pweight=weight]
#reg correct encourageguess if mturk==1
platforms <- data.frame(
	condition = factor(
			c( "Treatment effect\non DK responses", "Treatment effect\non DK responses", "Treatment effect\non DK responses", "Treatment effect\non correct responses", "Treatment effect\non correct responses", "Treatment effect\non correct responses" ),
			levels = c( "Treatment effect\non DK responses", "Treatment effect\non correct responses" ),
			ordered = TRUE
	),
	estimate = 	c(  -0.35, -0.13, -0.33,  0.10, 0.007, 0.30 ),
	lower = 	c(  -0.59, -0.34, -0.45, -0.18, -0.21, 0.14 ),
	upper = 	c(  -0.11,  0.08, -0.20,  0.37,  0.22, 0.46 ),
	Platform = factor( 
		c( "CCES", "Google", "MTurk" ),
		levels=c( "CCES", "Google", "MTurk" ), 
		ordered=TRUE 
	)
)
ggplot(
	data = platforms,
	aes( x=condition, y=estimate, ymin=lower, ymax=upper, colour=Platform )
) +
	theme_bw() +
	theme( aspect.ratio=5/3 ) +
	geom_point(position = position_dodge(width = 0.2)) +
	geom_errorbar(position = position_dodge(width = 0.2), width = 0.1)	 +
	scale_y_continuous( limits=c(-1.1,1.1), breaks=c(-1,0,1), name="Mean Effect of Encouraging Guessing Rather Than Encouraging DK", expand=c(0,0) ) +
	scale_x_discrete( name="" )


